package com.jxc.employee;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/employeeList")
public class LIstServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Employee> list = new ArrayList<>();
        ServletContext context = req.getServletContext();
        if (context.getAttribute("employees") == null){
            list.add(new Employee(1,"jxc","后端开发部","后端开发工程师",20000f));
            list.add(new Employee(2,"jxc2","前端开发部","前端开发工程师",15000f));
            list.add(new Employee(3,"jxc3","网络工程部","网络工程师",16000f));
        }
        context.setAttribute("employees",list);
        req.getRequestDispatcher("/employee.jsp").forward(req,resp);

    }
}
